package com.gome.spiderkit.task.monitor;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import org.apache.log4j.Logger;

import com.gome.spiderkit.common.AppConfiguer;
import com.gome.spiderkit.task.base.QuartzManager;
import com.gome.spiderkit.task.base.TriggerCron;

public class MonitorInit {
	private static Map<String, MonitorJob> jobMap = new HashMap<String, MonitorJob>();

	public static void createMonitorJob(String zkhost) {
		
		if (jobMap.containsKey(zkhost))
			return;
		
		MonitorJob monitorJob = new MonitorJob();
		
		jobMap.put(zkhost, monitorJob);
		
		try {
			monitorJob.connect(zkhost);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}
		
		try {
			TriggerCron trigger = new TriggerCron(AppConfiguer.getStringByKey("MonitorCron"));
			trigger.setName(monitorJob.getJobName());
			QuartzManager.addJob(monitorJob.getJobName(), monitorJob.getJob(), trigger.getTigger());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
